package com.mindskip.xzs.controller.student;

import com.mindskip.xzs.base.BaseApiController;
import com.mindskip.xzs.base.RestResponse;
import com.mindskip.xzs.domain.User;
import com.mindskip.xzs.service.ExamPaperService;
import com.mindskip.xzs.service.ExamRandomService;
import com.mindskip.xzs.utility.ExamUtil;
import com.mindskip.xzs.utility.QuestionTestUtil;
import com.mindskip.xzs.viewmodel.admin.exam.ExamPaperEditRequestVM;
import com.mindskip.xzs.viewmodel.student.exam.ExamPaperSubmitVM;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


@RestController("QuestionTestController")
@RequestMapping(value = "/api/student/test")
public class QuestionTestController extends BaseApiController {

    private ExamRandomService examRandomService;

    @Autowired
    public QuestionTestController(ExamRandomService examRandomService) {
        this.examRandomService = examRandomService;
    }


    @RequestMapping(method = RequestMethod.GET,path = "/clear")
    public String clear() {
        QuestionTestUtil.cache.clear();
        return "Success";
    }

    @RequestMapping(method = RequestMethod.POST)
    public RestResponse<ExamPaperEditRequestVM> getNextQuestion2(@RequestBody ExamPaperSubmitVM examPaperSubmitVM) {
        System.out.println("input = "+ examPaperSubmitVM);
        User currentUser = getCurrentUser();
        ExamPaperEditRequestVM nextQuestion = examRandomService.getNextQuestion(currentUser, examPaperSubmitVM);
        System.out.println(nextQuestion);
        return RestResponse.ok(nextQuestion);
    }
}
